package com.by.server.config.security;

import com.by.server.pojo.RespBean;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;

/**
 * description : 全局异常处理
 * author      : YuFei
 * data        : 2021/11/16 16:00
 */
@RestController
public class GlobalException {
    @ExceptionHandler(SQLException.class)
    public RespBean mysqlException(SQLException e) {
        if (e instanceof SQLIntegrityConstraintViolationException) {
            return RespBean.error("该数据有关联数据，操作失败");
        }
        return RespBean.error("数据库异常，操作失败");
    }
}
